home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / TEST.CPP < prev    next >
C/C++ Source or Header  |  1994-11-11  |  5KB  |  218 lines

  1. // TEST.CPP                                  1          1    6666
  2. // Dave Harris                                11         11   6
  3. // Compiled using Borland C++ ver 3.1       1 1        1 1   6666
  4. // 03-03-94                                  1     ..   1   6   6
  5. //                                           11111 .. 11111  666
  6. ////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "au.hpp"
  9.  
  10. /*********************************************************************/
  11. /* Define Statements */
  12. /*********************/
  13.  
  14. #define PROGRAM "TEST"    // Name of module
  15.  
  16. /*********************************************************************/
  17.  
  18. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  19. static BYTE archive_has_password(AU *au, char *file_name)
  20. {
  21.     ARC_HANDLE arc_handle;
  22.     ARC_RECORD record;
  23.     BYTE ret_code = FALSE;
  24.  
  25.     check_for_key();
  26.  
  27.     arc_handle.init(au, file_name);
  28.     for (;;)
  29.     {
  30.         if (arc_handle.get_record(au, &record) != 0)
  31.             break;
  32.         if (record.encrypted)
  33.         {
  34.             ret_code = TRUE;
  35.             break;
  36.         }
  37.     }
  38.  
  39.     arc_handle.deinit(au);
  40.     return ret_code;
  41. }
  42. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  43. static int test_one(AU *au, char *file_name, PACKAGE *package)
  44. {
  45.     char string[FLENGTH];     /* build the dos commands in the string */
  46.     int  did_rename;
  47.     int  ret_value;
  48.  
  49.     if (!au->no_extra)
  50.         au_printf(au, "@?6Testing @?1%s@?H\n", file_name);
  51.     act_log_printf(au, "   + TEST    : %s", file_name);
  52.  
  53.     if (package->test == NULL)
  54.     {
  55.         au_printf_error(au, "No testing method specified for %s\n", file_name);
  56.         press_any_key(au);
  57.         return 0;
  58.     }
  59.  
  60.     did_rename = rename_strict(au, package, au->source_directory, file_name);
  61.  
  62.     au->number_processed++;
  63.  
  64.     substitute_macros(string, package->test, NULL, NULL, NULL, file_name);
  65.  
  66.     if (!au->simulate)
  67.     {
  68.         ret_value = execute(au, string, au->output, NULL, package->memoryNeeded);
  69.  
  70.         if (did_rename)
  71.             rename_strict_back(au->source_directory, file_name);
  72.  
  73.         if (ret_value > 0)
  74.         {
  75.             if (archive_has_password(au, file_name))
  76.                 add_to_bad_list(au, au->source_directory, file_name, ret_value, 5);
  77.             else
  78.             {
  79.                 if (au->rename_to[0] != '\0')
  80.                 {
  81.                     rename(file_name, fit_mask(file_name, au->rename_to));
  82.                     fix_flist(au, file_name, fit_mask(file_name, au->rename_to));
  83.                 }
  84.  
  85.                 add_to_bad_list(au, au->source_directory, file_name, ret_value, 1);
  86.             }
  87.             return -1;
  88.         }
  89.     }
  90.     return 0;
  91. }
  92. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  93. static void quick_test_one(AU *au, char *file_name, ARC_HANDLE *arc_handle)
  94. {
  95.     int ret_code;
  96.     ARC_RECORD record;
  97.  
  98.     if (!au->no_extra)
  99.         au_printf(au, "@?6Quick Testing @?1%s@?H\n", file_name);
  100.     act_log_printf(au, "   + TEST -Q : %s", file_name);
  101.     au->number_processed++;
  102.  
  103.     for (;;)
  104.     {
  105.         ret_code = arc_handle->get_record(au, &record);
  106.         if (ret_code == EOF)
  107.             break;
  108.         else if (ret_code == -2)
  109.         {
  110.             add_to_bad_list(au, au->source_directory, file_name, 0);
  111.             return;
  112.         }
  113.     }
  114. }
  115. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  116. int test(AU *au, char *file_name)
  117. {
  118.     ARC_HANDLE arc_handle;
  119.  
  120.     check_for_key();
  121.  
  122.     arc_handle.init(au, file_name);
  123.     if (au->quick_test)
  124.     {
  125.         if (arc_handle.type > 0)
  126.             quick_test_one(au, file_name, &arc_handle);
  127.         arc_handle.deinit(au);
  128.     }
  129.     else
  130.     {
  131.         arc_handle.deinit(au);
  132.         if (arc_handle.type > 0)
  133.             return test_one(au, file_name, &au->package[arc_handle.type]);
  134.     }
  135.     return 0;
  136. }
  137. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  138. static void ReadCFGInfo(AU *au, CFG_HANDLE *cfg_handle)
  139. {
  140.     char string[200],
  141.          string2[200],
  142.          string3[200];
  143.  
  144.     for(EVER)
  145.     {
  146.         if (cfg_handle->read_line(au, string)==EOF)
  147.             break;
  148.  
  149.         split_string(string, string2);
  150.         split_string(string, string3);
  151.  
  152.         if (string2[0] == '\0')
  153.             continue;
  154.  
  155.         strcpy(au->curOpt, string2);
  156.         au->curVal = string3;
  157.         switch (toupper(string2[1]) << 8 | toupper(string2[0]))
  158.         {
  159.             case 'BE':                                          // Begin
  160.                 return;
  161.             case 'PA':
  162.                 au->pause = get_value(au, OFF | ON);
  163.                 break;
  164.             case 'RE':
  165.                 strcpy(au->rename_to, string3);
  166.                 break;
  167.             default:
  168.                 cfg_handle->invalid_option(au, string2);
  169.         }
  170.     }
  171. }
  172. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  173. static BYTE parse_comm_line(AU *au, char option, char *, PARSE_TYPE type)
  174. {
  175.     switch (type)
  176.     {
  177.     case PARSE_SINGLE_OPTION:
  178.         if (option == 'Q')
  179.         {
  180.             au->quick_test = TRUE;
  181.             return TRUE;
  182.         }
  183.         return FALSE;
  184.     case PARSE_PARAM_OPTION:
  185.         switch (option)
  186.         {
  187.             case 'P':
  188.                 au->pause = get_value(au, OFF | ON);
  189.                 break;
  190.             case '?':
  191.                 au_standard_opt_header(au, "Test",
  192.                     "@?3-Q@?H               Quick Test\n"
  193.                     "@?3-P@?Hon|off         Pause after bad archive found\n");
  194.                 exit (0);
  195.             default:
  196.                 au_invalid_option(au, PROGRAM, option);
  197.         }
  198.         return TRUE;
  199.     }
  200.     return FALSE;
  201. }
  202. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  203. int main_test(AU *au, int argc, char *argv[])
  204. {
  205.     ReadGlobalCFGInfo(au, au->cfg_file, PROGRAM, ReadCFGInfo);
  206.     generic_parse_comm_line(au, argc, argv, parse_comm_line);
  207.     process_files(au, test);
  208.  
  209.     if (!au->no_extra)
  210.         au_printf_c(au, 15, "\n\nFiles Tested = %d\n", au->number_processed);
  211.  
  212.     /* Prevent recursion when disp_bad_arcs is later called */
  213.     au->quick_test = FALSE;
  214.  
  215.     return 0;
  216. }
  217.  
  218.